package cn.wolfcode.rbac.util;


import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * 分页封装类
 * @version 1.0
 * @Author:Cao Zhijian
 * @DATE:2020/12/24 0024 22:03:06
 */
@Setter
@Getter
@NoArgsConstructor
public class PageResult {

    private Integer currentPage;    // 当前页
    private Integer pageSize;       // 每页显示的数据

    private List list;              // 集合相关的数据
    private Integer count;          // 总条数

    private Integer prePage;        // 上一页
    private Integer nextPage;       // 下一页
    private Integer totalPage;      // 总页数

    public PageResult(Integer currentPage, Integer pageSize, List list, Integer count) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.list = list;
        this.count = count;

        this.prePage = this.currentPage - 1 > 1 ? this.currentPage - 1 : 1;
        this.totalPage = this.count % this.pageSize == 0 ? this.count/this.pageSize : this.count / this.pageSize + 1;
        this.nextPage = this.currentPage + 1 < totalPage ? this.currentPage+1 : totalPage;
    }
}
